jqgrid將參數傳遞給方法 (jqgrid passing parameter to method)


問題描述

jqgrid將參數傳遞給方法 (jqgrid passing parameter to method)

I have the following example:

      var url = '@Url.Action("GetProgData", "Prog")' + '?lbId=' + labId;        

      $("#loginList").jqGrid({
       url: url,
       datatype: "json",
       colNames: ['PNum', 'Client', 'Salesperson', 'Email'],
       colModel: [ ...
       ......

The method looks like the following in c# MVC:

     public JsonResult GetLoginData(int rows, int page, string sidx, string sord, string searchField, string searchString, string searchOper, int? labId)

What I like to do is to pass the value of labId conditionally so I have the following but doesn't seem to pass labId as it return null:

       $("#LabId").change(function () {
        labId = $("#LabId").val();
        setupGrid(labId);
        $("#loginList").trigger("reloadGrid", [{ page: 1}]);
       });

Not sure when I do it in the .change of a dropdown the value of labID does't go through fine

‑‑‑‑‑

參考解法

方法 1:

I think that you can sent null as the value of labId if 

$("#loginList").jqGrid({
    url: '@Url.Action("GetProgData", "Prog")',
    postData: {
        lId: function () {
            var labId = $("#LabId").val();
            return labId === "" ? null : labId;
        }
    },
    datatype: "json",
    colNames: ['PNum', 'Client', 'Salesperson', 'Email',
    ...
});

If the above solution will not work, than you can do the following alternatively

$("#loginList").jqGrid({
    url: '@Url.Action("GetProgData", "Prog")',
    serializeGridData: function (data) {
        var labId = $("#LabId").val();
        return labId === "" ? data : $.extend(true, {}, data, {lId: labId});
    },
    datatype: "json",
    colNames: ['PNum', 'Client', 'Salesperson', 'Email',
    ...
});

(by Nate PetOleg)

參考文件

  1. jqgrid passing parameter to method (CC BY‑SA 3.0/4.0)

#jqgrid #asp.net-mvc #C#






相關問題

jqGrid SetCell 和 SaveCell 在關閉模式對話框後將單元格消隱 (jqGrid SetCell and SaveCell blanking out the cell after closing a modal dialog)

刪除jqGrid中的垂直線 (Remove vertical lines in jqGrid)

jqgrid將參數傳遞給方法 (jqgrid passing parameter to method)

grails - Spring Security 核心插件 - ajax 調用 - 無效的記住我令牌不匹配。 (grails - Spring Security Core Plugin - ajax call - Invalid remember-me token mismatch.)

jqgrid網格的設置頁面 (jqgrid setting page of grid)

無法檢索 Jqgrid 中選定行的 ID (Unable to retireve the ids of the Selected rows in Jqgrid)

hiển thị dữ liệu xml trong một cột trong Jqgrid (show xml data in one column in Jqgrid)

如果行號為真,我們如何對 jqgrid 的列進行排序? (How can we sort the column of jqgrid if row number is true?)

如何在免費 jqgrid 末尾刪除多餘的空列 (How to remove extra empty column in end of free jqgrid)

使用 jquery jqgrid (using jquery jqgrid)

在 jqGrid 中請求第 0 頁 (Requesting page 0 in jqGrid)

jqGrid 如何應用自定義過濾/搜索 (jqGrid how to apply custom filtering / search)







留言討論